<?php

require_once( '../../conf/conf.inc' );
require_once( PATH_FRAME.'/etwork.php' );

$etw = new etwork;
$etw->parseURL('edit/member', 2);

$etw->limitLevel = access::MODERATOR;
$etw->isEdit = true;

if (! isset($etw->pathParameters[0]) ) {
    
    $etw->setTemplate('member', TRUE, TRUE, 0);

    $etw->setPankuzu(array(
        array('dir'=>'', 'config'=>'index'),
        array('dir'=>'edit', 'config'=>'modelate')
    ));
    $etw->setTitle(array('member','list'));

    $loader = new modelLoader;
    $loader->model = 'member';
    $loader->order = @$etw->EX_GET['r'] ? $etw->EX_GET['r'] : '_update_date';
    $loader->alike = @$etw->EX_GET['s'];
    $loader->offset = @$etw->EX_GET['p'];
    $loader->returning = 'list';
    $etw->addLoader($loader);

    $etw->loadData();

} else if (isset($etw->pathParameters[0]) && isNumber($etw->pathParameters[0])) {

    $etw->setTemplate( 'member', true, false );
    $etw->addClearTemplate( null, 'member|solo'.$etw->pathParameters[0]);

    $etw->setPankuzu(array(
        array('dir'=>'', 'config'=>'index'),
        array('dir'=>'edit', 'config'=>'modelate'),
        array('dir'=>'edit/member', 'config'=>array('member','list'))
    ));
    if ($etw->pathParameters[0] > 0)
        $etw->setTitle(array('edit'),array('solo'=>'name'));
    else
        $etw->setTitle(array('member','newpost'));


    $etw->noCaching = true;

    $etw->jumpTo = URL_EDIT .'member';

    $loader = new modelLoader;
    $loader->model = 'member';
    $loader->solo = $etw->pathParameters[0];
    $loader->mapperParameters = array(
        'editor_id' => $etw->getUserId()
    );
    $loader->targetId = 'post_id';
    $loader->isEdit = TRUE;
    $etw->addLoader($loader);
    
    $etw->loadData();

} else if ($etw->pathParameters[0] == 'login_history') {

    if (!isset($etw->pathParameters[1]) && !isNumber($etw->pathParameters[1])) {
        Access::jump( URL_SITE . 'edit/member' );
    }

    $etw->setTemplate( 'history', true, true );
    $etw->setTemplateGroup( 'member');

    $etw->setPankuzu(array(
        array('dir'=>'', 'config'=>'index'),
        array('dir'=>'edit', 'config'=>'modelate'),
        array('dir'=>'edit/member', 'config'=>array('member','list'))
    ));
    $etw->setTitle(array('login','history'),array('list_count'=>'_name'));

    $loader = new modelLoader;
    $loader->model = 'member';
    $loader->offset = @$etw->EX_GET['p'];
    $loader->targetSelectFunction = 'findHistoryById';
    $loader->returning = 'list';
    $loader->mapperParameters = array(
        'member_id' => $etw->pathParameters[1]
    );
    $etw->addLoader($loader);
    
    $etw->loadData();
}

$etw->showFinal();


